package org.ssp.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import org.junit.Test;

public class httpRequest {
	/**
	 * 
	 * 
	 * java发起http请求
	 * 
	 * @param args
	 * @throws IOException
	 */
	public static String httpRequest(String picurl,String method,String outputStr) throws IOException {
		
		URL url=null;
		try {
			
			url = new URL(picurl);
			HttpURLConnection conn=(HttpURLConnection) url.openConnection();
			conn.setRequestMethod(method);
			conn.connect();
			
			
			//往服务器写内容
			if(null!=outputStr){
				OutputStream is=conn.getOutputStream();
				

				
			}
			
			
			//读取服务器返回的内容
			InputStream is=conn.getInputStream();
			InputStreamReader isr=new InputStreamReader(is,"utf-8");
			BufferedReader br=new BufferedReader(isr);
			StringBuffer buffer=new StringBuffer();
			String line=null;
			while((line=br.readLine())!=null){
				buffer.append(line);
			}
			//console显示
			System.out.println(buffer.toString());	
			
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		return null;
		
	}

  

}
